package com.example.doctor.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.common.support.Result;
import com.example.common.utils.RequestHelp;
import com.example.doctor.dto.req.*;
import com.example.doctor.dto.resp.*;
import com.example.doctor.service.PatientService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sifan
 * @PackagName:com.example.doctor.controller
 * @ClassName: PatientController
 * @Description:
 * @date:2021/1/19 19:08
 */
@RestController
@Api(tags = "分组管理")
@RequestMapping("/api/Patient")
public class PatientController {

    @Resource
    PatientService patientService;

    @ApiOperation(value = "分组列表")
    @PostMapping("/GroupList")
    public Result<List<GroupListRsp>> GroupList(){
        List<GroupListRsp> groupListRsps = patientService.GroupList();
        return Result.success(groupListRsps);
    }

    @ApiOperation(value = "患者 分组中的患者")
    @PostMapping("/GroupPatients")
    public Result<Map<String,Object>> GroupPatients(@RequestBody GroupPatientsReq groupPatientsReq){
        Map<String,Object> groupPatientsRsps = patientService.GroupPatients(groupPatientsReq);
        return Result.success(groupPatientsRsps);
    }

    @ApiOperation(value = "患者 未加入分组的患者")
    @PostMapping("/NoInGroupPatients")
    public Result<PageInfo<GroupPatientsDb>> NoInGroupPatients(@RequestBody GroupPatientsReq groupPatientsReq){
        PageInfo<GroupPatientsDb> groupPatientsRsps = patientService.NoInGroupPatients(groupPatientsReq);
        return Result.success(groupPatientsRsps);
    }

    @ApiOperation(value = "患者 编辑分组名称")
    @PostMapping("/EditGroupName")
    public Result<HashMap<String,Object>> EditGroupName(@RequestBody EditGroupNameReq editGroupNameReq){
        HashMap<String,Object> hashMap = patientService.EditGroupName(editGroupNameReq);
        return Result.success(hashMap);
    }

    @ApiOperation(value = "患者 添加分组")
    @PostMapping("/AddGroup")
    public Result<HashMap<String,Object>> AddGroup(@RequestBody AddGroupReq addGroupReq){
        HashMap<String,Object> hashMap = patientService.AddGroup(addGroupReq);
        return Result.success(hashMap);
    }

    @ApiOperation(value = "患者 删除分组")
    @PostMapping("/DelGroup")
    public Result<HashMap<String,Object>> DelGroup(@RequestBody DelGroupReq delGroupReq){
        HashMap<String,Object> hashMap = patientService.DelGroup(delGroupReq);
        return Result.success(hashMap);
    }

    @ApiOperation(value = "患者 编辑分组")
    @PostMapping("/EditGroup")
    public Result<HashMap<String,Object>> EditGroup(@RequestBody EditGroupReq editGroupReq){
        HashMap<String,Object> hashMap = patientService.EditGroup(editGroupReq);
        return Result.success(hashMap);
    }

    @ApiOperation(value = "患者 患者详情")
    @PostMapping("/PatientInfo")
    public Result<HashMap<String,Object>> PatientInfo(@RequestBody PatientInfoReq patientInfoReq){
        HashMap<String,Object> hashMap = patientService.PatientInfo(patientInfoReq);
        return Result.success(hashMap);
    }

    @ApiOperation(value = "西医电子处方列表")
    @PostMapping("/xRxList")
    public Result<PageInfo<xRxListRsp>> xRxList(@RequestBody xRxListReq xRxListReq){
        PageInfo<xRxListRsp> pageInfo = patientService.xRxList(xRxListReq);
        return Result.success(pageInfo);
    }

    @ApiOperation(value = "中医电子处方列表")
    @PostMapping("/zRxList")
    public Result<PageInfo<zRxListRsp>> zRxList(@RequestBody xRxListReq xRxListReq){
        PageInfo<zRxListRsp> pageInfo = patientService.zRxList(xRxListReq);
        return Result.success(pageInfo);
    }

    @ApiOperation(value = "就诊列表")
    @PostMapping("/DiagnosisList")
    public Result<PageInfo<DiagnosisListRsp>> DiagnosisList(@RequestBody xRxListReq xRxListReq){
        PageInfo<DiagnosisListRsp> pageInfo = patientService.DiagnosisList(xRxListReq);
        return Result.success(pageInfo);
    }

    @ApiOperation(value = "就诊详情（院内首诊）")
    @PostMapping("/DiagnosisIn")
    public Result<HashMap<String,Object>> DiagnosisIn(@RequestBody DiagnosisInReq diagnosisInReq){
        HashMap<String,Object> diagnosisInRsp = patientService.DiagnosisIn(diagnosisInReq);
        return Result.success(diagnosisInRsp);
    }

    @ApiOperation(value = "就诊详情（非本院首诊）")
    @PostMapping("/DiagnosisOut")
    public Result<HashMap<String,Object>> DiagnosisOut(@RequestBody DiagnosisInReq diagnosisInReq){
        HashMap<String,Object> diagnosisInRsp = patientService.DiagnosisOut(diagnosisInReq);
        return Result.success(diagnosisInRsp);
    }

    @ApiOperation(value = "患者电子处方", notes = "{\"PID\":患者ID}")
    @PostMapping("/PRxList")
    public Result<List<Map<String, Object>>> PRxList(HttpServletRequest request){
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        long PID = Jo.getLongValue("PID");
        List<Map<String, Object>> map = patientService.PRxList(0,1,PID);
        return Result.success(map);
    }
}
